<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>综合管理平台-登录</title>
    <link type="favicon" rel="shortcut icon" href="./static/img/favicon.ico" />
    <link rel="stylesheet" href="./static/css/bootstrap.css">
    <link rel="stylesheet" href="./static/css/init.css">
    <link rel="stylesheet" href="./static/less/common.css">
    <link rel="stylesheet" href="./static/less/login.css" />
    <link href="./static/css/spop.min.css" rel="stylesheet"/>
    <script src="./static/js/isLogin.js"></script>
</head>
<body>
    <div id="login">
        <!-- <div class="loading" v-if="isLoading">
            <div>
                <p>加载中，请稍后。。。</p>
            </div>
        </div> -->
        <div class="login-form-box row" id="con">
            <div class="logo-box col-lg-7 col-md-7 col-sm-12 col-xs-12">
                <div class="logo"><img src="./static/img/logo.png" alt=""></div>
                <div class="title">综合信息管理平台</div>
            </div>
            <div class="form">
                <form>
                    <div class="form-group username">
                        <input type="text" class="form-control"  :class="err == '1' ? 'err' : ''" v-model="username" id="username" placeholder="用户名">
                    </div>
                    <div class="form-group password">
                        <input type="password" class="form-control" :class="err == '2' ? 'err' : ''" v-model="password" id="password" placeholder="密码" autocomplete>
                    </div>
                    <div class="tips">{{tips}}</div>
                    <button type="button" class="btn btn-default" @click="submit">登&nbsp;&nbsp;录</button>
                </form>
            </div>
        </div>
        <div class="loading" v-show="isLoading">
            <div class="spinner">
                <div class="spinner-container container1">
                    <div class="circle1"></div>
                    <div class="circle2"></div>
                    <div class="circle3"></div>
                    <div class="circle4"></div>
                </div>
                <div class="spinner-container container2">
                    <div class="circle1"></div>
                    <div class="circle2"></div>
                    <div class="circle3"></div>
                    <div class="circle4"></div>
                </div>
                <div class="spinner-container container3">
                    <div class="circle1"></div>
                    <div class="circle2"></div>
                    <div class="circle3"></div>
                    <div class="circle4"></div>
                </div>
            </div>
        </div>
    </div>
    <script type='text/javascript'>
        window.addEventListener('error',function(e){
            if(e.message == '语法错误') {
                alert('错误！检测到您的浏览器版本过低，推荐下载最新版本的谷歌浏览器！');
                window.location.href = "https://dl.softmgr.qq.com/original/Browser/72.0.3626.121_chrome_installer.exe";
                // document.execCommand("Stop");
            };
        });
    </script>
    <script src="./static/js/jquery-3.3.1.min.js"></script>
    <script src="./static/js/bootstrap.js"></script>
    <script src="./static/js/vue.min.js"></script>
    <script src="./static/js/axios.min.js"></script>
    <script src="./static/api/api.js"></script>
    <script src="./static/js/Syunew6.js"></script>
    <script src="./static/js/spop.min.js"></script>
    <script>
        var loginApp = new Vue({
            el: '#login',
            data() {
                return {
                    isLoading: true,
                    username: '',
                    password: '',
                    err: '',
                    tips: '',
                    baseUrl: api.baseUrl,
                    isSafety: false,
                    times: 0,
                }
            },
            created() {
                this.init();
            },
            methods: {
                init() {
                    let _vm = this;
                    setTimeout(() => {
                        document.querySelector('#con').style.display = 'flex';
                        _vm.isLoading = false;
                    },2000);
                    document.onkeydown = (event) => {
                        let key = window.event.keyCode;
                        if(key == 13) {
                            this.submit();
                        }
                    }
                    _vm.通知('警告','未检测到安全密钥，将禁止超级管理员用户登录，请插入安全密钥！如已插入密钥请尝试重新拔插！','warning')
                    _vm.times ++;
                    window.notice.opt.autoclose = 1
                    this.safety()
                },

                //提示通知
                通知(title,msg,type) {
                    window.notice = spop({
                        template: '<h4 class="spop-title">'+title+'</h4>'+msg,
                        style: type,
                        autoclose: 0
                    });
                },

                //提示通知
                通知2(title,msg,type) {
                    spop({
                        template: '<h4 class="spop-title">'+title+'</h4>'+msg,
                        style: type,
                        autoclose: 3000
                    });
                },

                //安全检测
                safety() {
                    var bConnect=0;
                    let _vm = this;
                    function load()
                    {
                        if(navigator.userAgent.indexOf("MSIE")>0 && !navigator.userAgent.indexOf("opera") > -1) 
                        {
                            return;
                        }
                        try
                        {
                            var s_pnp=new SoftKey6W();
                            s_pnp.Socket_UK.onopen = function() 
                            {
                                bConnect=1;
                            } 
                            
                            s_pnp.Socket_UK.onmessage =function got_packet(Msg) 
                            {
                                var PnpData = JSON.parse(Msg.data);
                                if(PnpData.type=="PnpEvent")
                                {
                                    if(PnpData.IsIn) 
                                    {
                                        // _vm.tips = '';
                                        _vm.isSafety = true;
                                        _vm.times = 0;
                                        if(window.notice) {
                                            window.notice.close()
                                        }
                                    }
                                    else
                                    {
                                        // _vm.tips = '警告！未检测到安全密钥，请插入安全密钥！如已插入密钥请尝试重新拔插！';
                                        if(_vm.times === 0) {
                                            _vm.通知('警告','未检测到安全密钥，请插入安全密钥！如已插入密钥请尝试重新拔插！','warning')
                                            _vm.times ++;
                                            window.notice.opt.autoclose = 1
                                        }
                                        _vm.isSafety = false;
                                    }
                                }
                            } 
                            
                            s_pnp.Socket_UK.onclose = function()
                            {
                                _vm.通知2('警告','超级管理员请先安装安全密钥驱动，否则无法正常登录系统！','warning')
                            }
                        
                        
                    }
                    catch(e)  
                    {  
                            alert(e.name + ": " + e.message);
                            return false;
                        }  
                    
                    }
                    load()
                },

                submit() {
                    if(!this.username) {
                        this.err = '1';
                        this.tips = '请输入用户名！';
                        document.querySelector('#username').focus();
                        return false;
                    };
                    if(!this.password) {
                        this.err = '2';
                        this.tips = '请输入密码！';
                        document.querySelector('#password').focus();
                        return false;
                    };
                    let body = {
                        password: this.password,
                        userName: this.username
                    }
                    
                    api.login(body).then(res => {
                        if(res.data.status == 'success') {
                            
                            let save = (STORAGE_KEY,items) => {
                                let data = window.JSON.stringify(items);
                                try {
                                    window.sessionStorage.setItem(STORAGE_KEY,data);
                                } catch(e) {
                                    alert('请关闭浏览器的无痕模式,否则将无法进入系统！');
                                }
                                window.sessionStorage.setItem(STORAGE_KEY,data);
                            };
                            if(res.data.data.groupName == '超级管理员' && !this.isSafety) {
                                this.通知2('错误','未检测到安全密钥，禁止超级管理员登录系统！','error')
                                return false;
                            }
                            let userData = {
                                userName: this.username,
                                loginTime: new Date(),
                                roles: res.data.data.userAuthority,
                                headImg: res.data.data.userHeaderImage,
                                groupName: res.data.data.groupName
                            };
                            let key = 'userLoginInfo'
                            save(key,userData);
                            key = 'userData',
                            save(key,res.data.data);
                            let logbody = {
                                author: this.username,
                                moduleChileName: '登录',
                                moduleName: '用户',
                                operation: '登录系统'
                            }
                            let fn = "window.location.href = './index.html'";
                            this.recordLog(logbody,fn);
                            // window.location.href = './index.html'
                        }else {
                            this.tips = '登录失败：' + res.data.data.errMsg
                        }
                    }).catch(err => {
                        this.tips = '登录失败：服务器开小差了，请稍后再试！';
                        console.log(err)
                    })
                },

                recordLog(body,fn=false) {
                    api.updateLog(body).then(res => {
                        if(fn) {
                            let newFN = new Function(fn);
                            newFN();
                        }
                        console.log(res.data)
                    }).catch(err => {
                        console.error(err)
                    })
                }
            }
        })
    </script>
</body>

</html>